<?php
namespace app\admin\controller;

use app\common\model\BuddhistService as BuddhistServiceModel;
/**
 * 佛事预约控制器
 * Class BuddhistService
 * @package app\index\controller
 */
class BuddhistService extends Base
{
    /**
     * [getIndex  佛事预约列表]
     * @param
     * @return mixed|\think\response\Json
     * @author [C。]
     */
    public function getIndex()
    {
        $model = new BuddhistServiceModel;
        $param = input('param.');
        $this->getPageAndSize($param);
        $map = [];
        $user = $this->user;
        try{
            if (is_array($param)) {
                if (!empty($param['comname'])) {
                    $map['c.comname'] = ['like', "%" . $param['comname'] . "%"];
                }
                if (!empty($param['type'])) {
                    $map['b.type'] = $param['type'];
                }
                if(!empty($data['time_type'])){
                    if($data['time_type'] == 1){
                        $map['b.subtime'] = ['between',[strtotime($data['start']),strtotime($data['end'])]];
                    }
                    if($data['time_type'] == 2){
                        $map['b.addtime'] = ['between',[strtotime($data['start']),strtotime($data['end'])]];
                    }
                    if($data['time_type'] == 3){
                        $map['b.subtime|b.addtime'] = ['between',[strtotime($data['start']),strtotime($data['end'])]];
                    }
                }
                if(!empty($param['memid'])){
                    $map['b.memid'] = $param['memid'];
                }
            }
            $field = 'b.id,c.comname,b.type,b.isgo,b.name,b.tel,b.addr,b.subtime,b.remark,b.addtime';
            $count = $model->getCount($map);//满足条件的总数
            $allpage = intval(ceil($count / $this->size));//总页数
            $lists = $model->getlist($map,$this->from, $this->size,$field);
            foreach($lists as &$v){
                $v['subtime'] = date('Y-m-d',$v['subtime']);
                $v['addtime'] = date('Y-m-d H:i:s',$v['addtime']);
            }
        }catch(\Exception $e){
            systembug($e->getMessage(),1,'admin/BuddhistService/getIndex');
            return admin_json(-1, '获取失败'.$e->getMessage());
        }
        writelog('查看佛事预约列表',0,$user);
        return admin_json(1,'获取成功',[
            'count' => $count,//总记录数
            'allpage' => $allpage,  //总页数
            'lists' => $lists,  //列表数据
        ]);
    }
}